<template>
  <div>
    <template v-if="typeof(text)=='object'">
        <el-scrollbar  style="height: 430px;">
                <pre v-for="(str,key) in text">
             <div>{{key}}</div>
            <div>  {{ str }}</div>
          </pre>
        </el-scrollbar>
    </template>
    <template v-else>
      <pre>
        {{ text }}
    </pre>

    </template>

    <div>
      <button @click="()=>{
       triggerSearchShema()
      }">查询schema
      </button>
    </div>

  </div>
</template>
<script>

import searchShemabyname from '@/views/manage/swagger1/seeHtmlForm/searchShemabyname.vue';
import { openLayer } from '@/utils/layerdialog/layerdialog';

function safeParseJSON(str) {
  try {
    return JSON.parse(str);
  } catch (e) {
    console.warn(e);
    return '';
  }
}

export default {
  data() {
    return {
      safeParseJSON,
      searchComList: [1],
      queryParams: {
        schemaname: '',
      },
      JSON: window.JSON,
      text: '',
      parseShemas: [],
      activeShema: undefined,
    };
  },
  components: {
    searchShemabyname,
  },
  methods: {
    async initByDialog(_data) {
      var str = _data?.text;
      ;
      if (safeParseJSON(str)) {
        this.text = safeParseJSON(str);
      } else {
        this.text = str;
      }
      console.log('=>[this.text]', this.text);
    },
    async submitByDialog() {
      //validate
      //data operation
      //ajax 提交
      return { success: true };
    },
    async triggerSearchShema() {
      openLayer({
        title: '',
        components: {
          modify: () => import('@/views/manage/swagger1/seeHtmlForm/searchShemabyname.vue'),
        },
      });
    },

  },
};
</script>
